

// const jg_stu_id = wx.getStorageSync('jg_stu_id')
const domainName = getApp().globalData.domainName
const oss_domain = getApp().globalData.oss_domain
const parameter = getApp().globalData.parameter

const page_init=(that,jg_stu_id)=>{
  wx.showLoading({
    title: '别急，正在作法……',
  })
  wx.request({
    url: domainName + '/predict_ExamScore_init',
    data: {
      jg_stu_id:jg_stu_id
    },...parameter,
    success: res => {
      wx.hideLoading()
      predict(that, res.data.target1 || 0, res.data.target2 || 0)
    },
  })
}

const arr_list=(num_max)=>{
  var arr = []
  for(var i=0; i<num_max;i++){
    var num = i.toString()
    if(num.length==1){
      var num = '0'+ num
    }
    arr.push(num)
  }
  return arr
}



const predict=(that,target1,target2)=>{
that.arr1 = arr_list(99)
that.arr2 = arr_list(10)
that.count1 = 0
that.count2 = 0
that.timer_id1 = setInterval(() => {
  that.num_show1 = that.arr1[that.count1]
  that.setData({
    num_show1:that.num_show1,
  })
  that.count1 += 1
  if(that.count1==that.arr1.length){
    that.count1 = 0
    return
  }
  if(parseInt(that.num_show1)==target1){
    clearInterval(that.timer_id1)
  }
}, 100);

that.timer_id2 = setInterval(() => {
  that.num_show2 = that.arr2[that.count2]
  that.setData({
    num_show2:that.num_show2,
  })
  that.count2 += 1
  if(that.count2==that.arr2.length){
    that.count2 = 0
    return
  }
  if(parseInt(that.num_show2)==target2){
    clearInterval(that.timer_id2)
  }
}, 1000);

}

// pages/predict_ExamScore/predict_ExamScore.js
Page({


  /**
   * 页面的初始数据
   */
  data: {
    icon_url:oss_domain + 'static/picture/app_icon/',
    num_show1:'00',
    num_show2:'00',
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // console.log('options', options)
    let jg_stu_id = options.jg_stu_id
    if(jg_stu_id){
      page_init(this, jg_stu_id)
    }else{
      wx.showModal({
        content: '您好，该功能仅对在训学员开放',
        showCancel: false,
        title: '提示',
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.setData({
      windowHeight:wx.getSystemInfoSync().windowHeight
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})